//个人中心
import React, {Component} from 'react'
import {View, Text, Image, TouchableOpacity, Alert} from 'react-native'
import Helper from '../../helpers'
import styles from '../../configs/styles'
import {connect} from 'react-redux'

class personalIndex extends Component {
  static navigationOptions = ({navigation}) => {
    return {
      header: null
    }
  };
  goChangeSchool = ()=> {
    if(loginState.info.all_schools.length>1){
      this.props.navigation.navigate('change_school')
    }else{
      Alert.alert('没有其他可切换学校')
    }
  }
  render() {
    return (
      <View style={{flex: 1}} key={this.props.user.school_id}>
        <View style={{padding: 30, backgroundColor: '#4077f8', flexDirection: 'column'}}>
          <View style={{padding: 10, alignSelf: 'center', alignItems: 'center'}}>
            <Image source={Helper.avatar(loginState.info.avatar)} style={styles.lg_avatar}/>
            <Text style={[styles.text_white, {marginTop: 10, fontSize: 17}]}>{loginState.info.name}</Text>
          </View>
        </View>
        <TouchableOpacity onPress={()=>this.goChangeSchool()}
          style={{flexDirection: 'row', padding: 15, alignItems: 'flex-start', backgroundColor: 'white', marginBottom: 10}}>
          <View sytle={{flexDirection: 'row'}}>
            <Text>学校</Text>
          </View>
          <View style={{flex: 1, alignItems: 'flex-end'}}>
            <Text style={styles.apply_info_text}>{loginState.info.current_school} ></Text>
          </View>
        </TouchableOpacity>
        <TouchableOpacity onPress={()=>App.logout()} style={{padding: 15, alignItems: 'center', backgroundColor: 'white'}}><Text style={styles.text_danger}>注销登录</Text></TouchableOpacity>
      </View>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    user: state.user
  }
};

export default connect(mapStateToProps)(personalIndex)